Skip to content

Refactor the esphome implementation to simplify dependencies and interfaces#72

Merged
brownard merged 6 commits intomasterfrom
Refactor_ESPHome
Mar 29, 2026
Merged

Refactor the esphome implementation to simplify dependencies and interfaces#72
brownard merged 6 commits intomasterfrom
Refactor_ESPHome

Conversation

@brownard
Copy link
Copy Markdown
Owner

@brownard brownard commented Mar 27, 2026

The current implementation had the voice assistant as a subclass of a device, which meant it had dependencies on the device settings/server/entitites/etc. This was starting to get unwieldly, particularly when adding more entities, and required lots of stubbing when testing.

Instead prefer composition so that a voice assistant is a child 'component' of a 'voice satellite' device, so that it only needs to handle voice input/output/messages. This simplifies its dependencies and makes it easier to test in isolation.

Additionally the voice input/output interfaces exposed unnecessary properties and didn't properly update settings when changed, requiring the service to watch for changes. Rework them so that they only expose the minimal required interface and automatically update settings when necessary.

Generally simplify names and tidy up.

Planned future refactoring should properly separate the Android specific implementations, e.g. microphone and player implementations, from the esphome implementation to allow it to be pulled out to a, ideally pure JVM, module to allow reuse in e.g. Kotlin Multiplatform code, but this pull request is already big enough for now.

@brownard brownard marked this pull request as ready for review March 28, 2026 13:32
…e device to simplify dependencies/testing

- Remove voice satellite dependency on server, entities and settings. These only need to be known by the overarching 'device'
- Add an injectable device builder for building a voice satellite device from settings
- Update tests
- Get/set wake words and muted directly from/to data store to ensure its always the source of truth
- Rework voice input flow to recreate the detector when wake word settings change
- Remove now unnecessary settings watcher from VoiceSatelliteService
…ce for use with MediaPlayerEntity

- Remove properties that are only used internally from the VoiceOutput interface
- Add a separate MediaPlayer interface tor use with MediaPlayerEntity
- Don't expose the tts/media players, all calls should go through VoiceOutput/MediaPlayer interface
- Update StubVoiceOutput and tests
Reflects the naming in other ESPHome implementations and conceptually the voice assistant implementation is just one components of a larger 'voice satellite' device
@brownard brownard merged commit ff9b8f9 into master Mar 29, 2026
1 check passed
@brownard brownard deleted the Refactor_ESPHome branch March 29, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant